package com.hkts.management.unattended.poundroom.service.serviceimpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkts.management.unattended.poundroom.entity.YbMutualPovouch;
import com.hkts.management.unattended.poundroom.entity.YbMutualSovouch;
import com.hkts.management.unattended.poundroom.mapper.YbMutualSovouchMapper;
import com.hkts.management.unattended.poundroom.service.IYbMutualSovouchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zy
 * @since 2021-10-13
 */
@Service
@Transactional
@DS("slave")
public class YbMutualSovouchSlaveServiceImpl extends ServiceImpl<YbMutualSovouchMapper, YbMutualSovouch>  {


    @Autowired
    private YbMutualSovouchMapper ybMutualSovouchMapper;

    public IPage<YbMutualSovouch> selectPage(Page<YbMutualSovouch> page, YbMutualSovouch ybMutualSovouch){
        QueryWrapper<YbMutualSovouch> query=Wrappers.query();
        return ybMutualSovouchMapper.selectPage(page,query);
        }


    public List<YbMutualSovouch> selectList(YbMutualSovouch ybMutualSovouch){
        QueryWrapper<YbMutualSovouch> query=Wrappers.query();
        return ybMutualSovouchMapper.selectList(query);
        }
    public List<YbMutualSovouch> getUpdateTimeData(LocalDateTime updateTime,int flag){
        QueryWrapper<YbMutualSovouch> query = Wrappers.query();
        query.select("top 1000   autoID,iSOsID, cSOCode, dDate, cSTCode, cDepName, cPersonName, cCusCode, cCusAbbName, iStatus,cInvCode, cInvName, cInvStd, cComUnitName,iQuantity,WFHSL,dPreDate,  bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus");
        query.lambda().gt(updateTime!=null,YbMutualSovouch::getDoptTime,updateTime);
        query.orderByAsc("AutoID");
        if(flag!=0){
            Integer count=flag*1000;
            Integer maxId=ybMutualSovouchMapper.getAutoIdMax(count);
            query.lambda().ge(YbMutualSovouch::getAutoID,maxId);
        }
        return ybMutualSovouchMapper.selectList(query);
    }
    public Integer getUpdateTimeCount(LocalDateTime updateTime){
        QueryWrapper<YbMutualSovouch> query = Wrappers.query();
        query.lambda().gt(updateTime!=null,YbMutualSovouch::getDoptTime,updateTime);
        Integer count=ybMutualSovouchMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public Integer getBmutualStatusCount(){
        QueryWrapper<YbMutualSovouch> query = Wrappers.query();
        query.lambda().eq(YbMutualSovouch::getBmutualStatus,0);
        Integer count=ybMutualSovouchMapper.selectCount(query);
        double flag=count;
        double total=flag/1000;
        return (int)Math.ceil(total);
    }
    public List<YbMutualSovouch> getBmutualStatuData(int flag){
        QueryWrapper<YbMutualSovouch> query = Wrappers.query();
        query.select("top 1000   autoID,iSOsID, cSOCode, dDate, cSTCode, cDepName, cPersonName, cCusCode, cCusAbbName, iStatus,cInvCode, cInvName, cInvStd, cComUnitName,iQuantity,WFHSL,dPreDate,  bDel, doptTime, dcreateTime, dmodifyTime, ddeleteTime, u8optStatus, bmutualStatus");
        query.lambda().eq(YbMutualSovouch::getBmutualStatus,0);
        query.orderByAsc("AutoID");
        if(flag!=0){
            Integer count=flag*1000;
            Integer maxId=ybMutualSovouchMapper.getAutoIdMax(count);
            query.lambda().ge(YbMutualSovouch::getAutoID,maxId);
        }
        return ybMutualSovouchMapper.selectList(query);
    }

}
